import 'package:flutter/cupertino.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_tv_widgets/config/kq_global.dart';

import '../../resources/images.dart';
import '../../theme/kq_theme_manager.dart';

///KqCheckBox
class KqCheckBox extends StatelessWidget {
  ///初始值，默认未选择
  final bool value;

  ///宽
  final double? width;

  ///高
  final double? height;

  /// 是否可用，默认可用
  final bool enable;

  /// 是否部分选择
  final bool isHalfChecked;

  /// 按钮样式，默认圆角
  final CheckBoxStyle style;

  ///外层大小偏移，防止图片被截掉
  final double? offset;

  const KqCheckBox({
    super.key,
    this.value = false,
    this.width,
    this.height,
    this.enable = true,
    this.style = CheckBoxStyle.round,
    this.isHalfChecked = false,
    this.offset,
  });

  @override
  Widget build(BuildContext context) {
    return _buildWidget();
  }

  Widget _buildWidget() {
    return SizedBox(
      width: (width ?? 24.r) + (offset ?? 0.1.r),
      height: (height ?? 24.r) + (offset ?? 0.1.r),
      child: Align(
        alignment: Alignment.center,
        child: KqImage.assets(
          url: style == CheckBoxStyle.round
              ? (isHalfChecked
                  ? Images.commonIcCheckboxesSelectedEnabledLine
                  : (!enable
                      ? (value
                          ? Images.commonIcCheckboxesSelectedDisabledCircle
                          : Images.commonIcCheckboxesUnselectedDisabledCircle)
                      : (value
                          ? Images.commonIcCheckboxesSelectedEnabledCircle
                          : Images.commonIcCheckboxesUnselectedEnabledCircle)))
              : (isHalfChecked
                  ? Images.commonIcCheckboxesIndeterminateEnabledSquare
                  : (!enable
                      ? (value
                          ? Images.commonIcCheckboxesSelectedDisabledSquare
                          : Images.commonIcCheckboxesUnselectedDisabledSquare)
                      : (value
                          ? Images.commonIcCheckboxesSelectedEnabledSquare
                          : Images.commonIcCheckboxesUnselectedEnabledSquare))),
          package: KqGlobal.packageName,
          color: !enable || !value
              ? null
              : KqThemeManager.getCommonConfig().mainLightColor,
          width: width ?? 24.r,
          height: height ?? 24.r,
          fit: BoxFit.contain,
        ),
      ),
    );
  }
}

///按钮展示样式
enum CheckBoxStyle {
  ///圆角
  round,

  ///方形
  square
}
